home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / cp950ext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  5.3 KB  |  143 lines

  1.  
  2. /*
  3.  * CP950 extensions
  4.  */
  5.  
  6. static const unsigned short cp950ext_2uni_pagef9[157-116] = {
  7.   /* 0xf9 */
  8.                                   0x7881, 0x92b9, 0x88cf, 0x58bb,
  9.   0x6052, 0x7ca7, 0x5afa, 0x2554, 0x2566, 0x2557, 0x2560, 0x256c,
  10.   0x2563, 0x255a, 0x2569, 0x255d, 0x2552, 0x2564, 0x2555, 0x255e,
  11.   0x256a, 0x2561, 0x2558, 0x2567, 0x255b, 0x2553, 0x2565, 0x2556,
  12.   0x255f, 0x256b, 0x2562, 0x2559, 0x2568, 0x255c, 0x2551, 0x2550,
  13.   0x256d, 0x256e, 0x2570, 0x256f, 0x2593,
  14. };
  15.  
  16. static int
  17. cp950ext_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  18. {
  19.   unsigned char c1 = s[0];
  20.   if ((c1 == 0xf9)) {
  21.     if (n >= 2) {
  22.       unsigned char c2 = s[1];
  23.       if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {
  24.         unsigned int i = 157 * (c1 - 0xa1) + (c2 - (c2 >= 0xa1 ? 0x62 : 0x40));
  25.         unsigned short wc = 0xfffd;
  26.         {
  27.           if (i >= 13932 && i < 13973)
  28.             wc = cp950ext_2uni_pagef9[i-13932];
  29.         }
  30.         if (wc != 0xfffd) {
  31.           *pwc = (wchar_t) wc;
  32.           return 2;
  33.         }
  34.       }
  35.       return RET_ILSEQ;
  36.     }
  37.     return RET_TOOFEW(0);
  38.   }
  39.   return RET_ILSEQ;
  40. }
  41.  
  42. static const unsigned short cp950ext_2charset[41] = {
  43.   0xf9f9, 0xf9f8, 0xf9e6, 0xf9ef, 0xf9dd, 0xf9e8, 0xf9f1, 0xf9df,
  44.   0xf9ec, 0xf9f5, 0xf9e3, 0xf9ee, 0xf9f7, 0xf9e5, 0xf9e9, 0xf9f2,
  45.   0xf9e0, 0xf9eb, 0xf9f4, 0xf9e2, 0xf9e7, 0xf9f0, 0xf9de, 0xf9ed,
  46.   0xf9f6, 0xf9e4, 0xf9ea, 0xf9f3, 0xf9e1, 0xf9fa, 0xf9fb, 0xf9fd,
  47.   0xf9fc, 0xf9fe, 0xf9d9, 0xf9dc, 0xf9da, 0xf9d6, 0xf9db, 0xf9d8,
  48.   0xf9d7,
  49. };
  50.  
  51. static const Summary16 cp950ext_uni2indx_page25[10] = {
  52.   /* 0x2500 */
  53.   {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 }, {    0, 0x0000 },
  54.   {    0, 0x0000 }, {    0, 0xffff }, {   16, 0xffff }, {   32, 0x0001 },
  55.   {   33, 0x0000 }, {   33, 0x0008 },
  56. };
  57. static const Summary16 cp950ext_uni2indx_page58[12] = {
  58.   /* 0x5800 */
  59.   {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
  60.   {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 },
  61.   {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0000 }, {   34, 0x0800 },
  62. };
  63. static const Summary16 cp950ext_uni2indx_page5a[16] = {
  64.   /* 0x5a00 */
  65.   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
  66.   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
  67.   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 },
  68.   {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0000 }, {   35, 0x0400 },
  69. };
  70. static const Summary16 cp950ext_uni2indx_page60[6] = {
  71.   /* 0x6000 */
  72.   {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 }, {   36, 0x0000 },
  73.   {   36, 0x0000 }, {   36, 0x0004 },
  74. };
  75. static const Summary16 cp950ext_uni2indx_page78[9] = {
  76.   /* 0x7800 */
  77.   {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 },
  78.   {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 }, {   37, 0x0000 },
  79.   {   37, 0x0002 },
  80. };
  81. static const Summary16 cp950ext_uni2indx_page7c[11] = {
  82.   /* 0x7c00 */
  83.   {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 },
  84.   {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0000 },
  85.   {   38, 0x0000 }, {   38, 0x0000 }, {   38, 0x0080 },
  86. };
  87. static const Summary16 cp950ext_uni2indx_page88[13] = {
  88.   /* 0x8800 */
  89.   {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 },
  90.   {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 },
  91.   {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 }, {   39, 0x0000 },
  92.   {   39, 0x8000 },
  93. };
  94. static const Summary16 cp950ext_uni2indx_page92[12] = {
  95.   /* 0x9200 */
  96.   {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 },
  97.   {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 },
  98.   {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0000 }, {   40, 0x0200 },
  99. };
  100.  
  101. static int
  102. cp950ext_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  103. {
  104.   if (n >= 2) {
  105.     const Summary16 *summary = NULL;
  106.     if (wc >= 0x2500 && wc < 0x25a0)
  107.       summary = &cp950ext_uni2indx_page25[(wc>>4)-0x250];
  108.     else if (wc >= 0x5800 && wc < 0x58c0)
  109.       summary = &cp950ext_uni2indx_page58[(wc>>4)-0x580];
  110.     else if (wc >= 0x5a00 && wc < 0x5b00)
  111.       summary = &cp950ext_uni2indx_page5a[(wc>>4)-0x5a0];
  112.     else if (wc >= 0x6000 && wc < 0x6060)
  113.       summary = &cp950ext_uni2indx_page60[(wc>>4)-0x600];
  114.     else if (wc >= 0x7800 && wc < 0x7890)
  115.       summary = &cp950ext_uni2indx_page78[(wc>>4)-0x780];
  116.     else if (wc >= 0x7c00 && wc < 0x7cb0)
  117.       summary = &cp950ext_uni2indx_page7c[(wc>>4)-0x7c0];
  118.     else if (wc >= 0x8800 && wc < 0x88d0)
  119.       summary = &cp950ext_uni2indx_page88[(wc>>4)-0x880];
  120.     else if (wc >= 0x9200 && wc < 0x92c0)
  121.       summary = &cp950ext_uni2indx_page92[(wc>>4)-0x920];
  122.     if (summary) {
  123.       unsigned short used = summary->used;
  124.       unsigned int i = wc & 0x0f;
  125.       if (used & ((unsigned short) 1 << i)) {
  126.         unsigned short c;
  127.         /* Keep in `used' only the bits 0..i-1. */
  128.         used &= ((unsigned short) 1 << i) - 1;
  129.         /* Add `summary->indx' and the number of bits set in `used'. */
  130.         used = (used & 0x5555) + ((used & 0xaaaa) >> 1);
  131.         used = (used & 0x3333) + ((used & 0xcccc) >> 2);
  132.         used = (used & 0x0f0f) + ((used & 0xf0f0) >> 4);
  133.         used = (used & 0x00ff) + (used >> 8);
  134.         c = cp950ext_2charset[summary->indx + used];
  135.         r[0] = (c >> 8); r[1] = (c & 0xff);
  136.         return 2;
  137.       }
  138.     }
  139.     return RET_ILSEQ;
  140.   }
  141.   return RET_TOOSMALL;
  142. }
  143.